package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: SetmealController
 * Description:
 *
 * @Author HTAO
 * @Create 2023/11/2 21:01
 */
@RestController
@Api(tags = "套餐管理")
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;
    @PostMapping
    @ApiOperation("新增套餐")
    public Result AddSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("查询套餐")
    public Result<PageResult> querySetmeal(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("按照页数查询：{}:",setmealPageQueryDTO);
        PageResult pageResult =setmealService.querySetmeal(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> queryaSetmeal(@PathVariable Long id){
        log.info("按照id查询：{}:",id);
        SetmealVO result =setmealService.queryaSetmeal(id);
        return Result.success(result);
    }
    @DeleteMapping
    @ApiOperation("删除套餐")
    public Result deleteSetmeal(@RequestParam List<Long> ids){
        log.info("删除套餐：{}:",ids);
        setmealService.deleteSetmeawithother(ids);
        return Result.success();
    }

    @PostMapping("status/{status}")
    @ApiOperation("更改套餐状态")
    public Result updateStatus(@PathVariable Integer status,Long id){
        log.info("更改状态");
        setmealService.updateStatus(status,id);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("更改套餐所有")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("更改套餐");
        setmealService.update(setmealDTO);
        return Result.success();
    }


}
